<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/friend.php');
require_once ('../lib/test.php');
require_once ('../../simpletest/autorun.php');
require_once ('../lib/init.php');
require_once ('../data_sample/mockup_data_post.php');

class TestFunc_processFriendPost extends UnitTestCase {
    
    function setUp(){
        global $login_button,$facebook;
        
        //if there is a session, skip code for processting sesseion
        if(isLoggedIn()){
            try{
                $me = getOneself();
            }catch(Exception $e){
                print($login_button);
                exit();
            }
        }
    }
    
    //Case5: A friend wrote a post on my wall
    function test_case5(){ 
        global $postCase5;
        $data = $postCase5;
        $friends = array();
        
        processFriendPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertTrue(count($friends) == 1);
        $friend = $friends['100000416787478'];
        $this->assertTrue($friend->getNumberOfData("FRIEND_POST_FLAG") == 1);
        
    }
    
    //Case6: A friend wrote two posts on my wall
    function test_case6(){ 
        global $postCase6;
        $data = $postCase6;
        $friends = array();
        
        processFriendPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertEqual(count($friends),1);
        
        $friend = $friends['100000416787478'];
        $this->assertEqual($friend->getNumberOfData("FRIEND_POST_FLAG"),2);
    }
    
    //Case7: Friends wrote posts on my wall (complicated), yool(3), soon(2)
    function test_case7(){ 
        global $postCase7;
        $data = $postCase7;
        $friends = array();
        
        processFriendPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertEqual(count($friends),2);
        
        $friend = $friends['100000416787478'];
        $this->assertEqual($friend->getNumberOfData("FRIEND_POST_FLAG"),3);
        
        $friend = $friends['100000525262538'];
        $this->assertEqual($friend->getNumberOfData("FRIEND_POST_FLAG"),2);
    }
    
    function test_real_data(){
        $friends = array();
        $posts = getFriendPost();
        
        processFriendPost($friends, $posts);

        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertTrue(count($friends) > 0);
        
    }
}
?>
